const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
// 需要额外地引入vueloader的插件
const { VueLoaderPlugin } = require("vue-loader");

module.exports = {
  mode: "production",
  entry: "./src/main.js",
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "index.js",
  },
  module: {
    rules: [
      {
        test: /\.less$/i,
        use: [
          // compiles Less to CSS
          "style-loader",
          "css-loader",
          "less-loader",
        ],
      },
      {
        test: /\.vue$/,
        loader: "vue-loader",
      },
    ],
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, "./public/index.html"),
    }),
    new VueLoaderPlugin(),
  ],
  devServer: {
    port: 5173,
    // 反向代理,用于做前端跨域的
    proxy: {
      // key应该写地址的路径的第一段
      "/api": {
        // target要写地址的协议域名和端口号
        target: "https://i.maoyan.com",
        changeOrigin: true,
      },
    },
  },
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src/"),
      com: path.resolve(__dirname, "src/components/"),
    },
    extensions: [".js", ".json", ".wasm", ".vue"],
  },
};
